package com.xiaoyu.lanling.feature.invite.viewholder

import `in`.srain.cube.views.list.ViewHolderBase
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.xiaoyu.base.app.AppContext
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.invite.model.InviteBoardItem
import com.xiaoyu.lanling.media.image.ImageViewUtil
import com.xiaoyu.lanling.view.UserAvatarDraweeView
import com.xiaoyu.lanling.view.text.UserNameTextView

class InviteBoardViewHolder : ViewHolderBase<InviteBoardItem>() {
    private lateinit var rank: TextView
    private lateinit var avatar: UserAvatarDraweeView
    private lateinit var name: UserNameTextView
    private lateinit var money: TextView
    override fun createView(layoutInflater: LayoutInflater, parent: ViewGroup): View {
        val rootView = layoutInflater.inflate(R.layout.invite_board_item, parent, false)
        rank = rootView.findViewById(R.id.rank)
        avatar = rootView.findViewById(R.id.avatar)
        name = rootView.findViewById(R.id.user_name)
        money = rootView.findViewById(R.id.money)
        return rootView
    }

    override fun showData(position: Int, itemData: InviteBoardItem) {
        if (position < 3) {
            rank.setBackgroundResource(R.drawable.invite_rank_background)
        } else {
            rank.background = null
        }
        rank.text = (position + 1).toString()
        rank.setTextColor(if (position < 3) AppContext.getColor(R.color.colorWhite) else AppContext.getColor(R.color.invite_earning_text))
        ImageViewUtil.loadImage(avatar, itemData.loadParam)
        name.setUser(itemData.user)
        money.text = itemData.money
    }
}